{extend name="base" /}
{block name="body"}
<style>
    body {
        background-color: #f2f2f2;
        padding: 15px;
    }
    .topic-container {
        background-color: #fff;
        border-radius: 2px;
        box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
        padding: 15px;
        margin-bottom: 15px;
    }
    .reply-container {
        background-color: #fff;
        border-radius: 2px;
        box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
        padding: 15px;
    }
    .reply-item {
        padding: 15px 0;
        margin-bottom: 15px;
    }
    .system-reply {
        text-align: left;
    }
    .user-reply {
        text-align: right;
    }
    .admin-reply {
        text-align: left;
        background-color: #fff;
        padding: 10px;
        /*border-left: 3px solid #FFB800;*/
    }
    .reply-user {
        font-weight: bold;
        color: #666;
    }
    .system-reply .reply-user {
        color: #1E9FFF;
    }
    .user-reply .reply-user {
        color: #FF5722;
    }
    .admin-reply .reply-user {
        color: #FFB800;
    }
    .reply-time {
        color: #999;
        font-size: 12px;
        margin-left: 10px;
    }
    .reply-content {
        margin-top: 10px;
        color: #333;
        line-height: 1.6;
        padding: 10px;
        border-radius: 4px;
        display: inline-block;
        max-width: 70%;
        word-break: break-word;
    }
    .system-reply .reply-content {
        background-color: #f0f9ff;
        border: 1px solid #d0e6ff;
        text-align: left;
    }
    .user-reply .reply-content {
        background-color: #fff8f0;
        border: 1px solid #ffddb3;
        text-align: left;
    }
    .admin-reply .reply-content {
        background-color: #fffdf5;
        border: 1px solid #ffe7a9;
        text-align: left;
    }
    .topic-image {
        max-width: 100%;
        margin: 15px 0;
        border-radius: 4px;
    }
    .reply-form {
        margin-top: 20px;
        padding-top: 20px;
        border-top: 1px dashed #eee;
    }
    .admin-tools {
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid #eee;
    }
</style>

<div class="layui-body">
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('/admin/message')}">客服中心</a></li>
            <li class="layui-this">消息列表</li>
        </ul>


        <div class="layui-tab-content">
            <!-- 话题标题和内容 -->
            <div class="topic-container">
                <h1>{$msg['content']['desc']}</h1>
                <div class="layui-row" style="margin: 10px 0;">
                    <div class="layui-col-md6">
                        <span><i class="layui-icon layui-icon-user"></i> UID: {$msg['uid']}&nbsp;&nbsp; 账号: {:get_player($msg['uid'],'account')}</span>
                        <span style="margin-left: 10px;"><i class="layui-icon"></i> 游戏: {:get_game_filed($msg['content']['gid'],'name')}</span>
                        {notempty name="$msg['content']['server']"}
                            <span style="margin-left: 10px;"><i class="layui-icon"></i> 区服: {$msg['content']['server']}</span>
                        {/notempty}
                        {notempty name="$msg['content']['character']"}
                            <span style="margin-left: 10px;"><i class="layui-icon"></i> 角色: {$msg['content']['character']}</span>
                        {/notempty}
                    </div>
                    <div class="layui-col-md6" style="text-align: right;">
                        <span><i class="layui-icon layui-icon-time"></i> 发布时间: {$msg['create_time']}</span>
                        {/*<span class="layui-badge layui-bg-orange" style="margin-left: 10px;">精华帖</span>*/}
                    </div>
                </div>

                <!-- 话题图片 -->
                {notempty name="images"}
                    <div class="topic-image">
                    {foreach name="images" item="img"}
                        <img style="width: 100px;height: 100px;" onclick="openModal(this)" src="{:getImgeUrl($img)}">
                    {/foreach}
                    </div>
                {/notempty}
            </div>

            <!-- 回复列表 -->
            <div class="reply-container">
            {notempty name="msg_list"}
                {foreach name="msg_list" item="vo"}
                    {if condition="$vo['type'] == 0"}
                        <!-- 系统回复 -->
                        <div class="reply-item admin-reply">
                            <div>
                                <span class="reply-user"><i class="layui-icon layui-icon-username"></i> 系统回复</span>
                                <span class="reply-time">{$vo['update_time']}</span>
                                {/*<span class="layui-badge layui-bg-orange" style="margin-left: 5px;">官方</span>*/}
                            </div>
                            <div class="reply-content">
                                {$vo['content']}
                            </div>
                        </div>
                    {else}
                        <!-- 用户回复 -->
                        <div class="reply-item user-reply">
                            <div>
                                <span class="reply-time">{$vo['update_time']}</span>
                                <span class="reply-user"><i class="layui-icon layui-icon-user"></i>{:get_player($vo['uid'],'account')}</span>
                            </div>
                            <div class="reply-content">
                                {notempty name="$vo['content']"}
                                    {$vo['content']}
                                {/notempty}
                                {notempty name="$vo['images']"}
                                    <div class="topic-image">
                                        {foreach name=":explodeImg($vo['images'])" item="img"}
                                            <img style="width: 100px;height: 100px;" onclick="openModal(this)" src="{:getImgeUrl($img)}">
                                        {/foreach}
                                    </div>
                                {/notempty}
                            </div>
                        </div>
                    {/if}
                {/foreach}
            {/notempty}

                <!-- 回复表单 -->
                <div class="reply-form" style="background-color: #f8f8f8;">
                    <form class="layui-form" action="">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">管理员回复</label>
                            <div class="layui-input-block">
                                <textarea name="content" placeholder="请输入回复内容" class="layui-textarea" id="reply-content"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn layui-bg-orange" lay-submit lay-filter="formReply"><i class="layui-icon layui-icon-username"></i> 提交回复</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                <button data-action="{:url('/admin/message/close',['id'=>$msg['id']])}" class="layui-btn layui-btn-danger layui-btn-mini ajax-action">已解决</button>
                                </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>


    </div>
</div>
{/block}
{block name="script"}
<script>

    // 点击放大图片
    function openModal(img) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 1,
            area: ['auto', 'auto'],
            skin: 'layui-layer-nobg',
            shadeClose: true,
            content: '<img src="' + img.src + '" style="width: 500px;height: 900px;">'
        });
    }



    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.$;

        // 监听回复表单提交
        form.on('submit(formReply)', function(data){
            var content = data.field.content;
            if(content.trim() === '') {
                layer.msg('回复内容不能为空');
                return false;
            }

            // 这里应该是Ajax提交到服务器
            // layer.msg('回复成功', {icon: 1});
            // 消息回复
            var url = "{:url('/admin/message/reply')}";
            var id = "{$msg['id']}";
            var data = {customer_id:id,type:0,content:content};
            $.post(url,data,function(info){
                layer.msg(info.msg);
            })
            // 模拟添加管理员回复到列表
            var newReplyHtml = '<div class="reply-item admin-reply">' +
                    '<div><span class="reply-user"><i class="layui-icon layui-icon-username"></i> 管理员回复</span>' +
                    '<span class="reply-time">刚刚</span></div>' +
                    '<div class="reply-content">' + content + '</div></div>';

            $('.reply-form').before(newReplyHtml);
            $('#reply-content').val('');

            return false;
        });
    });
</script>
{/block}